package com.government.member.service.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.government.common.core.domain.entity.SysUser;
import com.government.member.domain.VipInfo;
import com.government.member.mapper.VipInfoMapper;
import com.government.member.mapper.VipMapper;
import com.government.member.service.VipInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

import static com.government.common.utils.SecurityUtils.getLoginUser;

@Service
@Transactional(rollbackFor = Exception.class)
public class VipInfoServiceImpl implements VipInfoService {
    @Autowired
    private VipInfoMapper vipInfoMapper;
    @Autowired
    private VipMapper vipMapper;

    @Override
    public VipInfo selectVipInfoById(Long id) {

        return vipInfoMapper.selectById(id);
    }

    @Override
    public List<VipInfo> selectVipInfoList() {
//        SysUser sysUser = getLoginUser().getUser();


        List<VipInfo> vipInfoList = vipInfoMapper.selectList(Wrappers.<VipInfo>lambdaQuery().orderByAsc(VipInfo::getSort));
        for (VipInfo vipInfo : vipInfoList) {
           vipInfo.setMaturityTime(DateUtil.formatDate(DateUtil.offsetMonth(new Date(),vipInfo.getTime())));
        }

        return vipInfoList;
    }


}
